package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.ReturnList;
import com.atguigu.jxc.entity.ReturnListGoods;
import com.atguigu.jxc.service.ReturnListService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/returnListGoods")
public class ReturnListController {

    @Resource
    private ReturnListService returnListService;

    @PostMapping("save")
    public ServiceVO returnListGoods(ReturnList returnList, String returnListGoodsStr){

        List<ReturnListGoods> lists = new Gson().fromJson(returnListGoodsStr, new TypeToken<List<ReturnListGoods>>(){}.getType());

        for (ReturnListGoods list : lists) {
            returnListService.getReturnList(returnList,list);
        }

        return new ServiceVO(100, "请求成功");

    }
}
